import vue2 from '@vitejs/plugin-vue2';
import { defineConfig, loadEnv } from 'vite'
import { resolve } from 'path';

export default defineConfig(({ mode }) => {
  const { VITE_PORT, VITE_BASE_URL } = loadEnv(mode, process.cwd());
  return defineConfig({
    base: VITE_BASE_URL,
    plugins: [
      vue2()
    ],
    resolve: {
      extensions: [".vue", ".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"],
      alias: {
        '@': resolve(__dirname, 'src'),
        'echarts': 'echarts/dist/echarts.js',
        $: "jquery",
        jQuery: "jquery",
        'window.jquery': "jquery",
        'echarts-liquidfill': 'echarts-liquidfill/dist/echarts-liquidfill.js',
        'echarts-wordcloud': 'echarts-wordcloud/dist/echarts-wordcloud.js'
      },
    },
    css: {
      preprocessorOptions: {
        less: {
          modifyVars: {
            hack: `true; @import (reference) "${resolve('src/static/css/common.css')}";`,
          },
          math: 'strict',
          javascriptEnabled: true
        }
      }
    },
    server: {
      // 是否开启 https
      https: false,
      // 端口号
      port: VITE_PORT,
      // 监听所有地址
      host: '0.0.0.0',
      // 服务启动时是否自动打开浏览器
      open: true,
      // 允许跨域
      cors: true,
      // 自定义代理规则
      proxy: {},
    },
    build: {
      target: 'es2015',
      sourcemap: false,
      chunkSizeWarningLimit: 2000,
      reportCompressedSize: false
    }
  })
})


